package com.ruoyi.web.controller.construction;

import java.util.List;

import com.ruoyi.system.domain.construction.RentalLabel;
import com.ruoyi.system.service.construction.RentalLabelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租赁服务规格Controller
 * 
 * @author 张少丛
 * @date 2021-01-09
 */
@RestController
@RequestMapping("/construction/label")
public class RentalLabelController extends BaseController
{
    @Autowired
    private RentalLabelService rentalLabelService;

    /**
     * 查询租赁服务规格列表
     */
//    @PreAuthorize("@ss.hasPermi('construction:label:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentalLabel rentalLabel)
    {
        startPage();
        List<RentalLabel> list = rentalLabelService.selectRentalLabelList(rentalLabel);
        return getDataTable(list);
    }

    /**
     * 导出租赁服务规格列表
     */
//    @PreAuthorize("@ss.hasPermi('construction:label:export')")
    @Log(title = "租赁服务规格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RentalLabel rentalLabel)
    {
        List<RentalLabel> list = rentalLabelService.selectRentalLabelList(rentalLabel);
        ExcelUtil<RentalLabel> util = new ExcelUtil<RentalLabel>(RentalLabel.class);
        return util.exportExcel(list, "label");
    }

    /**
     * 获取租赁服务规格详细信息
     */
//    @PreAuthorize("@ss.hasPermi('construction:label:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Integer labelId)
    {
        return AjaxResult.success(rentalLabelService.selectRentalLabelById(labelId));
    }

    /**
     * 新增租赁服务规格
     */
//    @PreAuthorize("@ss.hasPermi('construction:label:add')")
    @Log(title = "租赁服务规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalLabel rentalLabel)
    {
        return toAjax(rentalLabelService.insertRentalLabel(rentalLabel));
    }

    /**
     * 修改租赁服务规格
     */
//    @PreAuthorize("@ss.hasPermi('construction:label:edit')")
    @Log(title = "租赁服务规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalLabel rentalLabel)
    {
        return toAjax(rentalLabelService.updateRentalLabel(rentalLabel));
    }

    /**
     * 删除租赁服务规格
     */
//    @PreAuthorize("@ss.hasPermi('construction:label:remove')")
    @Log(title = "租赁服务规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Integer[] labelIds)
    {
        return toAjax(rentalLabelService.deleteRentalLabelByIds(labelIds));
    }
}
